<template>
	<view class="pageBox">
		<view class="list">
			<view class="listItem" v-for="item in list" :key="item.id">
				<view class="top flex-row">
					<view class="defaultText flex-center" v-if="item.status == 1">
						默认
					</view>
					<view class="topR">
						{{item.name}}&nbsp;&nbsp;&nbsp;&nbsp;{{item.mobile}}
					</view>
					<view class="check-icon" v-if="isSelect" @click="onSelectItem(item)">
						<image class="check-icon-img" src="http://www.bobei.shop/static/login/choosed.png" v-if="selectId == item.id">
						</image>
						<image class="check-icon-img" src="http://www.bobei.shop/static/login/choose.png" v-else></image>
					</view>
				</view>

			<!-- 	<view class="center">
					{{item.address}}
				</view> -->

				<view class="bom flex-between">
					<view class="bomL">
						{{item.province}}{{item.city}}{{item.area}}{{item.address}}
						<!-- {{item.name}}&nbsp;&nbsp;&nbsp;&nbsp;{{item.mobile}} -->
					</view>
					<view class="bomR flex">
						<image class="icon" src="http://www.bobei.shop/static/third/my/Slice 163.png" mode=""
							@click.stop="goEdite(item.id)"></image>
						<image class="icon" src="http://www.bobei.shop/static/third/my/Slice 164.png" mode="" @click.stop="onDelBtn(item.id)">
						</image>
					</view>
				</view>
			</view>
		</view>

		<view class="bomBox flex-center">
			<button class="btn" :plain="true" @click="goEdite()">添加收货地址</button>
		</view>

		<my-popup-tips :showTips="showTips">
			<view class="tipsBox">
				<view class="tipsTitle flex-center">
					提示
				</view>

				<view class="tipsText flex-center">
					确定要删除该地址吗？
				</view>

				<view class="tipsBtnBox flex-between">
					<button class="tipsCloseBtn" :plain="true" @click="onTipsCloseBtn">取消</button>
					<button class="tipsSureBtn" :plain="true" @click="onTipsSureBtn">确定</button>
				</view>
			</view>
		</my-popup-tips>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showTips: false,
				list: [],
				temp: "",
				isSelect: false,
				selectId: "",
				eventChannel: null,
			}
		},
		methods: {
			onDelBtn(id) {
				this.temp = id;
				this.showTips = true;
			},
			onTipsCloseBtn() {
				this.showTips = false;
			},
			onTipsSureBtn() {
				this.showTips = false;
				this.$post({
					module: "User",
					interface: "6002",
					data: {
						id: this.temp
					}
				}).then(() => {
					uni.showToast({
						title: "删除成功",
						icon: "none",
						duration: 1500
					})
					setTimeout(() => this.getList(), 1000)
				})
			},
			goEdite(id = "") {
				uni.navigateTo({
					url: '/serviceCenter/addressEdite?id=' + id,
				})
			},
			getList() {
				this.$post({
					module: "User",
					interface: "6000"
				}).then(res => {
					// // console.log("地址列表", res)
					this.list = res;
				})
			},
			onSelectItem(item) {
				this.eventChannel.emit("select", item);
				uni.navigateBack();
			}
		},
		onShow() {
			this.getList();
		},
		onLoad(e) {
			if (typeof e.select === "string") {
				this.selectId = e.select;
				this.isSelect = true;
			}
			this.eventChannel = this.getOpenerEventChannel();

		}
	}
</script>

<style scoped lang="scss">
	.pageBox {
		padding: 0 32rpx;

		.list {
			padding-bottom: 120rpx;

			.listItem {
				padding: 32rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 2rpx 8rpx 0rpx rgba(212,212,212,0.25);
				border-radius: 24rpx;
				margin-bottom: 24rpx;
				.top {
					.defaultText {
						width: 60rpx;
						height: 24rpx;
						background: rgba(242,97,95,0.2965);
						border-radius: 8rpx;
						font-size: 16rpx;
						color: #F2615F;
						margin-right: 10rpx;
						
					}

					.topR {
						flex: 1;
						font-size: 36rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 600;
						color: #000000;
						line-height: 40rpx;
						margin-bottom: 10rpx;
					}

					.check-icon {
						width: 44rpx;
						height: 44rpx;

						.check-icon-img {
							width: 100%;
							height: 100%;
							vertical-align: middle;
						}
					}
				}

				.center {
					font-size: 32rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #000000;
					line-height: 40rpx;
					margin-top: 10rpx;
				}

				.bom {
					.bomL {
						font-size: 28rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #afa9b0;
						line-height: 40rpx;
					}

					.bomR {
						margin-top: 32rpx;

						.icon {
							width: 32rpx;
							height: 32rpx;
							margin-left: 32rpx;

						}
					}
				}
			}
		}

		.bomBox {
			width: 100%;
			height: 120rpx;
			background-color: #ffffff;
			position: fixed;
			bottom: 40rpx;
			left: 0;
			z-index: 1;
			.btn {
				padding: 0;
				margin: 0;
				border: none;
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #ffffff;
				line-height: 40rpx;
				width: 682rpx;
				height: 72rpx;
				border-radius: 52rpx;
				background: linear-gradient(256deg, #F2615F 0%, #FEA20E 100%);
			}
		}

		.tipsBox {
			width: 550rpx;
			background: #FFFFFF;
			border-radius: 32rpx;
			padding: 64rpx 48rpx;

			.tipsTitle {
				font-size: 32rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #000000;
				line-height: 40rpx;
			}

			.tipsText {
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #736464;
				line-height: 40rpx;
				margin-top: 48rpx;
			}

			.tipsBtnBox {
				width: 100%;
				margin-top: 90rpx;

				button {
					padding: 0;
					margin: 0;
					width: 200rpx;
					height: 72rpx;
					border-radius: 52rpx;
					font-size: 28rpx;
				}

				.tipsCloseBtn {
					color: #F2615F;
					border: 2rpx solid #F2615F;
				}

				.tipsSureBtn {
					color: #ffffff;
					border: none;
					background: #F2615F;
				}
			}
		}
	}
</style>
